#ifndef __AHUFSM_H__
#define __AHUFSM_H__

#include "includecopy.h"

/* 系统状态机类型 */
typedef enum _ahu_st_tp_e{
    S_INIT = 0,     // 必须从0开始，要和ahu_sysfsmset[]的第0个成员对应
    S_SF_ONWAIT,    // 等待新风阀开启确认状态
    S_IDLE
}ahu_st_tp_e;

/* 事件类型 */
typedef enum _ahu_ev_tp_e{
    /* 系统状态机事件 */
    EV_SYS_START    =   0,
    EV_SYS_STOP     =   1,
    EV_SF_ON        =   2,
    EV_SF_OFF
}ahu_ev_tp_e;

/* 状态机转移 */
typedef struct _ahu_fsmtrans_t{
    ahu_ev_tp_e event;
    int (*pre)(void *);        // 预处理，判断是否满足状态转移条件
    int (*action)(void *);     // 执行，执行成功，状态就变成下一个状态了
    int (*end)(void *);        // 收尾
    ahu_st_tp_e next_state;
}ahu_fsmtrans_t;

/* 状态机转移集合 */
typedef struct _ahu_fsmsets_t{
    char name[30];
    int num;
    ahu_fsmtrans_t *ahu_fsm;
}ahu_fsmsets_t;

typedef struct _ahu_fsm_t{
    ahu_fsmsets_t *fsmset;
    int fsmno;

    ahu_st_tp_e pre_state;
    ahu_st_tp_e cur_state;

    ahu_ev_tp_e fsmevt;         // 记录当前收到的事件

}ahu_fsm_t;

void send_event(ahu_dev_t_copy *ahu_dev, ahu_ev_tp_e evt);

void *ahu_state_ck_thread(void *arg);

void fsm_do(ahu_ev_tp_e evt, ahu_dev_t_copy *ahu_dev);

enum error_code ahu_fsmpre_null(void *);
enum error_code ahu_fsmaction_null(void *);
enum error_code ahu_fsmend_null(void *);

enum error_code fsm_init_2sf_onwait(void *arg);

enum error_code fsm_sf_onwait_2idle_pre(void *arg);
enum error_code fsm_sf_onwait_2idle(void *arg);

enum error_code fsm_sf_onwait_2init_pre(void *arg);
enum error_code fsm_sf_onwait_2init(void *arg);

enum error_code fsm_idle_2init(void *arg);



#endif // __AHUFSM_H__